package net.learn.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.utils.Result;
import net.learn.system.query.SysRadioQuery;
import net.learn.system.query.SysSubjectQuery;
import net.learn.system.service.SysPaperService;
import net.learn.system.service.SysSubjectService;
import net.learn.system.vo.SysRadioVO;
import net.learn.system.vo.SysSubjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 科目管理
 */
@RestController
@RequestMapping("sys/subject")
@Tag(name="科目管理")
@AllArgsConstructor
public class SysSubjectController {
    @Autowired
    private final SysSubjectService sysSubjectService;

    @GetMapping("getSubject")
    @Operation(summary = "分页")
    public Result<PageResult<SysSubjectVO>> getSubject(@Valid SysSubjectQuery query){
        PageResult<SysSubjectVO> page = sysSubjectService.qrySubjectListPage(query);
        return Result.ok(page);
    }
    @PostMapping("getSubjectList")
    @Operation(summary = "获取学科列表")
    public Result<List<SysSubjectVO>> getSubjectList(@RequestBody @Valid SysSubjectQuery query){
        List<SysSubjectVO> list = sysSubjectService.qrySubjectList();

        return Result.ok(list);
    }
    @PutMapping
    @Operation(summary = "修改")
    public Result<String> updateSubject(@RequestBody @Valid SysSubjectVO vo){
        sysSubjectService.updateSubject(vo);

        return Result.ok();
    }

    @PostMapping("save")
    @Operation(summary = "保存")
    public Result<String> save(@RequestBody SysSubjectVO vo){
        sysSubjectService.addSubject(vo);

        return Result.ok();
    }
    @DeleteMapping
    @Operation(summary = "删除")
    public Result<String> delete(@RequestBody List<Long> idList){
        sysSubjectService.delVideoById(idList);
        return Result.ok();
    }
}

